$(function () {

    // 绑定微信接口
    var bindUrl = '/o2o/local/bindlocalauth';
    var usertype = getQueryString('usertype');

    /**
     * 提交
     */
    $('#submit').click(function () {
        var userName = $('#username').val();
        var password = $('#psw').val();
        var verifyCodeActual = $('#j_captcha').val();

        var needVerify = false;
        if (!verifyCodeActual) {
            $.toast('请输入验证码!');
            return;
        }

        //访问后台，绑定微信
        $.ajax({
            url: bindUrl,
            async: false,
            cache: false,
            type: 'post',
            dataType: 'json',
            data: {
                userName: userName,
                password: password,
                verifyCodeActual: verifyCodeActual
            },
            success: function (data) {
                if(data.success){
                    $.toast('绑定成功！');
                    if(usertype == 1){
                        //若用户在前端站式系统页面自动退回前端站式系统首页
                        window.location.href = '/o2o/frontend/index';
                    }else{
                        //若用户是在店家管理系统页面则自动退回店铺列表页中
                        window.location.href = '/o2o/shopadmin/shoplist';
                    }
                }else{
                    $.toast('提交失败！'+data.errMsg);
                    $('#captcha_img').click();
                }
            }
        });
    });

})